package net.huashitong.ssydt.provider.exam.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.huashitong.ssydt.PaginationResult;
import net.huashitong.ssydt.exam.entity.SsExamPaper;
import net.huashitong.ssydt.exam.entity.vo.ExamPaperEditInVO;
import net.huashitong.ssydt.exam.entity.vo.ExamPaperInVO;
import net.huashitong.ssydt.exam.entity.vo.ExamPaperQueryInVO;
import net.huashitong.ssydt.provider.exam.service.SsExamPaperService;
import net.huashitong.ssydt.provider.web.model.Result;
import net.huashitong.ssydt.provider.web.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 试卷管理（后台）
 *
 * @author hemj
 * @version 2017/9/11
 */
@Api(value = "/exam/paper", tags = {"试卷管理（后台）"})
@RestController
@RequestMapping("/exam/paper")
public class SsExamPaperController {

	private SsExamPaperService ssExamPaperService;

	@Autowired
	public SsExamPaperController(SsExamPaperService ssExamPaperService) {
		this.ssExamPaperService = ssExamPaperService;
	}

	@ApiOperation(value = "试卷列表分页查询", notes = "试卷列表分页查询")
	@GetMapping
	public Result<PaginationResult<SsExamPaper>> paginationQuery(@ModelAttribute ExamPaperQueryInVO examPaperQueryInVO) {
		return ResultUtils.getSuccessResults(ssExamPaperService.paginationQuery(examPaperQueryInVO));
	}

	@ApiOperation(value = "加载试卷信息", notes = "加载试卷信息(包含答案选项列表)")
	@GetMapping("/{paperId}")
	public Result<SsExamPaper> get(@PathVariable Long paperId) {
		return ResultUtils.getSuccessResults(ssExamPaperService.getById(paperId));
	}

	@ApiOperation(value = "新增试卷", notes = "新增试卷")
	@PostMapping
	public Result<String> post(@Valid @RequestBody ExamPaperInVO examPaperInVO) {
		ssExamPaperService.insertExamPaper(examPaperInVO);
		return ResultUtils.getSuccessResults();
	}

	@ApiOperation(value = "修改试卷", notes = "修改试卷")
	@PutMapping("/{paperId}")
	public Result<String> put(@PathVariable Long paperId, @Valid @RequestBody ExamPaperEditInVO examPaperEditInVO) {
		examPaperEditInVO.setId(paperId);
		ssExamPaperService.updateExamPaper(examPaperEditInVO);
		return ResultUtils.getSuccessResults();
	}

}
